package com.leyou.sh.trade.web;

import com.leyou.sh.trade.dto.OrderDTO;
import com.leyou.sh.trade.dto.OrderFormDTO;
import com.leyou.sh.trade.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author balisong_fcs
 * @date 2021/1/17 22:03
 * @desc
 */
@RestController
@RequestMapping("/order")
@EnableFeignClients(basePackages = "com.leyou.sh.user.client")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping
    public ResponseEntity<Long> createOrder(
            @RequestBody @Valid OrderFormDTO orderFormDTO
    ) {
        return ResponseEntity.ok(this.orderService.createOrder(orderFormDTO));
    }
    /**
     * 根据id查询订单
     * @param orderId 订单id
     * @return 订单对象
     */
    @GetMapping("{id}")
    public ResponseEntity<OrderDTO> queryOrderById(@PathVariable("id") Long orderId){
        return ResponseEntity.ok(this.orderService.queryOrderById(orderId));
    }

}
